package cn.car.biz.convert;

import cn.car.domains.info.*;
import cn.car.domains.vo.zc.*;
import cn.car.utils.CarStringUtil;
import org.springframework.stereotype.Component;

@Component
public class ZsHttpConvert {

    public PlateDetectedInternalInfo parsePlateDetectedRequest(ZSPlateDetectedRequest request) {
        PlateDetectedInternalInfo plateDetectedInternalInfo = new PlateDetectedInternalInfo();
        AlarmInfoPlateReq alarmInfoPlate = request.getAlarmInfoPlate();
        InternalCameraInfo internalCameraInfo = new InternalCameraInfo();
        internalCameraInfo.setIp(alarmInfoPlate.getIpAddr());
        internalCameraInfo.setChannel(alarmInfoPlate.getChannel());


        AlarmInfoPlateReq.PlateResult plateResult = alarmInfoPlate.getResult().getPlateResult();
        final String license = plateResult.getLicense();
        final String imageFragmentFile = plateResult.getImageFragmentFile();
        final String imageFile = plateResult.getImageFile();
        InternalVehicleInfo internalVehicleInfo = new InternalVehicleInfo();
        internalVehicleInfo.setPlateNumber(CarStringUtil.decodeUnicode(license));
        internalVehicleInfo.setPlateImgBase64(imageFragmentFile);
        internalVehicleInfo.setVehicleImgBase64(imageFile);

        plateDetectedInternalInfo.setCameraInfo(internalCameraInfo);
        plateDetectedInternalInfo.setVehicleInfo(internalVehicleInfo);
        return plateDetectedInternalInfo;

    }





    public AlarmInfoPlateResp parsePlateDetectedResult(Boolean result,Boolean isSnap) {

        AlarmInfoPlateResp responseAlarmInfoPlate = new AlarmInfoPlateResp();
        //**************    臻识对象数据结构    **************
        responseAlarmInfoPlate.setInfo(result ? "ok" : "no");

        if (isSnap) {
            AlarmInfoPlateResp.TriggerImage TriggerImage = new AlarmInfoPlateResp.TriggerImage();
            TriggerImage.setSnapImageRelativeUrl("/api/zsCameraPush/snapshotIn");
            responseAlarmInfoPlate.setTriggerImage(TriggerImage);
        }

        return responseAlarmInfoPlate;
    }

    public InternalHeartDataInfo parseZSHeartbeatRequest(ZSHeartbeatRequest request) {
        InternalHeartDataInfo internalHeartDataInfo = new InternalHeartDataInfo();
        internalHeartDataInfo.setIp(request.getIpaddr());
        return internalHeartDataInfo;
    }

    public InternalGIoInInfo parseZSGIOInRequest(ZSGIOInRequest request) {

        InternalGIoInInfo internalGIoInInfo = new InternalGIoInInfo();

        AlarmGIOInReq alarmGioIn = request.getAlarmGioIn();
        internalGIoInInfo.setSource(alarmGioIn.getResult().getTriggerResult().getSource());
        internalGIoInInfo.setValue(alarmGioIn.getResult().getTriggerResult().getValue());
        internalGIoInInfo.setIp(request.getAlarmGioIn().getIpaddr());
        internalGIoInInfo.setDeviceName(request.getAlarmGioIn().getDeviceName());

        return internalGIoInInfo;
    }
}
